# coding=utf-8
# @Time   : 2023/11/26
# @Author : wangjl
# @Email  : 1975039138@qq.com
from cachetools import TTLCache


class RequestCache(object):
    def __init__(self, max_size: int = 16384, ttl: int = 12*60*60):
        """
        TTLCache
        :param max_size: max number of records
        :param ttl: ttl for TTLCache (second)
        """
        self.max_size = max_size
        self.ttl = ttl
        self._cache = TTLCache(maxsize=self.max_size, ttl=self.ttl)

    def get(self, key: str, default_value=None):
        return self._cache.get(key, default=default_value)

    def put(self, key: str, value):
        if key not in self._cache:
            self._cache[key] = value
